package ru.edu.usu.cs.bubbles.userlistener;

import java.util.Vector;
import ru.edu.usu.cs.bubbles.utils.CoordConvertor;
import ru.edu.usu.cs.bubbles.utils.Point;

public class Trace {
    
    private Vector<Point> mCenters;
    private Vector<Float> mLengths;
    private Vector<Float> mAngles;
    
    private Trace(Vector<Point> centers,Vector<Float> lengths,Vector<Float> angles) {
        mCenters = centers;
        mLengths = lengths;
        mAngles = angles;
    }
    
    public static Trace fromVector(Vector<Point> vec) {
        int segmentsAmount = vec.size()-1;
        Vector<Point> centers = new Vector<Point>();
        Vector<Float> lengths = new Vector<Float>();
        Vector<Float> angles = new Vector<Float>();
        if (segmentsAmount==0) {
            centers.add(CoordConvertor.ScreenToWorld(vec.firstElement()));
            lengths.add(0f);
            angles.add(0f);
            return new Trace(centers,lengths,angles);
        }
        for (int i = 1;i<segmentsAmount;i++) {
            Point point_a = CoordConvertor.ScreenToWorld(vec.get(i-1));
            Point point_b = CoordConvertor.ScreenToWorld(vec.get(i));
            centers.add(new Point(
                    (point_b.x-point_a.x)/2,(point_b.y-point_a.y)/2));
            lengths.add(new Float(Math.sqrt(
                    (point_b.x-point_a.x)*(point_b.x-point_a.x) +
                    (point_b.y-point_a.y)*(point_b.y-point_a.y))));
            angles.add(new Float(Math.atan(
                    (point_b.y-point_a.y)/(point_b.x-point_a.x))));
        }
        return new Trace(centers,lengths,angles);
    }
    
    public Point getCenter(int i) {
        return mCenters.elementAt(i);
    }
    
    public float getLength(int i) {
        return mLengths.elementAt(i);
    }
    
    public float getAngle(int i) {
        return mAngles.elementAt(i);
    }
    
}
